from PySide6.QtCore import Qt
from PySide6.QtWidgets import QLineEdit


class EditableLineEdit(QLineEdit):
    # 重写QLineEdit
    def mouseDoubleClickEvent(self, event):
        self.setReadOnly(False)
        self.selectAll()
        super().mouseDoubleClickEvent(event)

    def keyPressEvent(self, event):
        if event.key() == Qt.Key.Key_Return or event.key() == Qt.Key.Key_Enter:
            self.setReadOnly(True)
            self.submit()
        else:
            super().keyPressEvent(event)

    def focusOutEvent(self, event):
        super().focusOutEvent(event)
